﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{    
    public partial class JLTAB50BSData : BaseFunction
    {
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        /*public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }

        SETINTEXDB INTEXDB = new SETINTEXDB();
         */
        public JLTAB50BSData()
            : base()
        {
        }
         public JLTAB50BSData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetAB50(DataRow dwTABEL)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "AB50";
            string FROMDATE = dwTABEL["FROMDATE"].ToString().Trim();
            string ENDDATE = dwTABEL["ENDDATE"].ToString().Trim();            
            try
            {
                orlReadCommand = INTEXDBC.OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT b.abkkdauftnr,a.abpneudat,a.abpneuben,a.abpart,TRIM(C.GSHANDLNR) AS ARTDESC, "
                    + " a.abpsollmenge5*0.01 as orderqty,a.abpzugkg*0.01 as alloqty, "
                    + " TRIM(b.abkaufttxt1||b.abkaufttxt2) AS REMARK "
                    + " FROM ABPOS A,ABKOPF B,GSDAT C "
                    + " WHERE A.ABPMANDANT = B.ABKMANDANT AND A.ABPAUFKRS = B.ABKAUFKRS "
                    + " AND A.ABPAUFLFD = B.ABKAUFLFD AND A.ABPAUFKRS = 'BS' "
                    + " AND A.ABPMANDANT = C.GSMANDANT AND A.ABPART = C.GSART "
                    + " AND A.ABPVAR = C.GSVAR "
                    + " and a.abpneudat >= '" + FROMDATE + "' and a.abpneudat <='" + ENDDATE + "' "
                    + " ORDER BY abpneudat "
                    ;

                Result = INTEXDBC.Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    byte[] b;
                    string value;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["ARTDESC"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["ARTDESC"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["REMARK"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["REMARK"] = value;
                    }
                }
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public DataSet BuildData(DataRow dwUI)
        {
            /*DataSet SResult = new DataSet();
            SETINTEXDB SReturn = new SETINTEXDB(); */
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetAB50(dwUI);
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

    }
}